/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chessboard;

import java.awt.Point;
import javax.media.j3d.Group;
import javax.media.j3d.Switch;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3f;

/**
 *
 * @author Jedrek
 */
class FigureTransformGroup extends TransformGroup{

    public static int iFigureCount = 0;
    //types of figures
    public static final int PAWN = 4;
    public static final int ROOK = 8;
    public static final int KNIGHT = 16;
    public static final int BISHOP = 32;
    public static final int QUEEN = 64;
    public static final int KING = 128;

    //colors
    public static final int WHITE = 1;
    public static final int BLACK = 2;

    public int iID;
    public int iType;
    public int iOriginalType;
    public int iColor;
    public boolean bAlive = true;
    public Point pPosition;
    public int wasMoved = 0;
    public Switch switchNode;

    public FigureTransformGroup(int type, int color){
        super();
        this.setCapability(FigureTransformGroup.ALLOW_TRANSFORM_WRITE);
        pPosition = new Point();
        iFigureCount++;
        iID = iFigureCount;
        iColor = color;
        iType = type;
        iOriginalType = iType;
        switchNode = new Switch(0);
        switchNode.setCapability(Switch.ALLOW_SWITCH_WRITE);
        switchNode.setCapability(Switch.ALLOW_SWITCH_READ);
        switchNode.setCapability(Switch.ALLOW_CHILDREN_EXTEND);
        switchNode.setCapability(Switch.ALLOW_CHILDREN_WRITE);
        switchNode.setCapability(Switch.ALLOW_CHILDREN_READ);
        addChild(switchNode);
    }

    public void setPosition(Point position){
        pPosition = (Point)(position.clone());
        Transform3D trans = new Transform3D();
        trans.set(BoardPos2RealPos(pPosition));
        this.setTransform(trans);
        wasMoved++;
    }

    public void setPosition(int x, int y){
        pPosition.x = x;
        pPosition.y = y;
        Transform3D trans = new Transform3D();
        trans.set(BoardPos2RealPos(pPosition));
        this.setTransform(trans);
        wasMoved++;
    }

    /**
     * @param boardPosision.x position in big letters
     * @param boardPosision.y position in numbers
     * @return
     */
    static Vector3f BoardPos2RealPos(Point boardPosition){
        return new Vector3f(3.5f - boardPosition.x, 0f, boardPosition.y - 3.5f);
    }

    /**
     * @param x position in big letters
     * @param y position in numbers
     * @return
     */
    static Vector3f BoardPos2RealPos(int x, int y){
        return new Vector3f(3.5f - x, 0f, y - 3.5f);
    }
}
